﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.JShop.UI;
using CNVP.Framework;
using System.Data;
using CNVP.Framework.Utils;
using CNVP.Framework.Helper;

namespace CNVP.JShop.Web.Member
{
    public partial class MyReview : UserPage
    {
        BLL.CNVP_Order bll = new BLL.CNVP_Order();
        Model.CNVP_Order model = new Model.CNVP_Order();
        public int rplistCount = 0;
        int PageIndex = 1;
        string productId;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["Page"]) && Public.IsNumber(Request.QueryString["Page"]))
            {
                PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            }
            productId = Request.QueryString["ProductID"];
            if (string.IsNullOrEmpty(productId) || !Public.IsNumber(productId))
            {
                productId = "0";
            }
            if (!IsPostBack)
            {

                StartLoad(PageIndex);
            }
        }
        
        /// <summary>
        /// 分页加载列表函数
        /// </summary>
        protected void StartLoad(int PageIndex)
        {
            int i, j;
            DataTable dt = null;
            int pageNum = 20;
            SQLConditionInfo[] st = new SQLConditionInfo[3];
            st[0] = new SQLConditionInfo("@olbid", "4,5,6,7");
            st[1] = new SQLConditionInfo("@oBuyerID", CookieUserID);
            st[2] = new SQLConditionInfo("@ProductID", productId);
            dt = bll.GetPageReview(this.GetType().Name, PageIndex, pageNum, out i, out j,st);
            rpList.DataSource = dt;
            rpList.DataBind();
            paging.InnerHtml = Paginator.Pagination(PageIndex, i, j);
        }

        public string OrderProductsImg(int OrderID)
        {
            string html = string.Empty;
            BLL.CNVP_OrderProducts bll_OrderProducts = new BLL.CNVP_OrderProducts();
            var list = bll_OrderProducts.GetAll_CNVP_OrderProducts(OrderID);
            for (int i = 0; i < list.Count; i++)
            {
                html += "<li class=\"MyReviewPro\">";
                html += "<a href=\"/ProductDetail_" + list[i].ProductClassID + "_" + list[i].ProductID + ".aspx\" target=\"_blank\" title=\"" + list[i].ProductName + "\"><img src=\"/UploadFile/Product/" + list[i].ImgProLoad + "\" height=\"80px\" width=\"80px\" /></a>";
                html += "<p>购买了：" + list[i].ProductName + " </p>";
                if (list[i].BuyerRate == 1)//已经评论
                {
                    html += "<a href=\"javascript:void(0)\" onclick=\"OpenModalWinByLook(" + list[i].ProductID + "," + list[i].ID + "," + list[i].ReviewID + ")\">查看评论</a>";
                }
                else
                {
                    //html += "<a href=\"/Controls/WriteReview.aspx?ProductID=" + list[i].ProductID + "&OrderProductsID=" + list[i].ID + "\" target=\"_blank\">立即评论</a>";

                    html += "<a href=\"javascript:void(0)\" onclick=\"OpenModalWin(" + list[i].ProductID + "," + list[i].ID + ")\">立即评论</a>";
                }
                html += "</li>";
            }
            return html;
        }


    }
}